package com.example.service.implService;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.dao.NotificationDao;
import com.example.mapper.NotificationMapper;
import com.example.pojo.Notification;
import com.example.pojo.NotificationReadStatus;
import com.example.pojo.dto.NotificationDTO;
import com.example.service.NotificationService;
import javafx.scene.effect.MotionBlur;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;

@Service
public class NotificationServiceImpl implements NotificationService {
    @Resource
    private NotificationDao notificationDao;

    @Resource
    private NotificationMapper notificationMapper;

    @Override
    public List<Notification> notificationList() {
        return notificationDao.notificationList();
    }

    // 分页查询
    @Override
    public IPage<Notification> getNotificationInfoPage(int currentPage, int limit) {
        return notificationDao.getNotificationInfoPage(currentPage,limit);
    }



    @Override
    public IPage<Notification> getNotificationByTitleInfoPage(int currentPage, int limit, String title) {
        return notificationDao.getNotificationByTitleInfoPage(currentPage,limit,title);
    }

    @Override
    public String addOrUpdateNotification(Notification notification) {
        if(Objects.isNull(notification.getNotificationId())){
            notification.setPublishDate(LocalDateTime.now());
        }
        return notificationDao.addOrUpdateNotification(notification);
    }

    @Override
    public String addNotificationForAllParents(Notification notification){
        if(Objects.isNull(notification.getNotificationId())){
            notification.setPublishDate(LocalDateTime.now());
        }
        return notificationDao.addNotificationForAllParents(notification);
    }

    @Override
    public int deleteNotificationFor(Notification notification) {
        return notificationMapper.deleteById(notification);
    }

    @Override
    public int batchNotificationInfo(List<Long> ids) {
        return notificationMapper.deleteBatchIds(ids);
    }

    @Override
    public String isReadNotification(NotificationReadStatus notificationReadStatus) {
        return notificationDao.isReadNotification(notificationReadStatus);
    }

    @Override
    public List<NotificationDTO> getNotificationByUserIdAndType(Long userId, Integer notificationType) {
        if(notificationType == 0){
            return notificationDao.getNotificationByUserId(userId);
        } else if (notificationType == 3) {
            // 查询自己的通知
            return notificationDao.getMyNotification(userId);
        }
        return notificationDao.getNotificationByUserIdAndType(userId, notificationType);
    }

    @Override
    public List<NotificationDTO> getNotReadNotificationByUserIdAndType(Long userId, Integer notificationType) {
        return notificationDao.getNotReadNotificationByUserIdAndType(userId, notificationType);
    }
}
